package com.hundred.item.module.screen;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.service.requestcontext.parser.ParameterParser;
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.util.TurbineUtil;
import com.hundred.item.dao.dataobject.ItemDO;
import com.hundred.item.dao.dataobject.ItemReqDO;
import com.hundred.item.manager.ItemManager;

public class AysnProcessSelected {
	
	private static final Logger log = LoggerFactory.getLogger(AysnProcessSelected.class);
	
	@Autowired
    private HttpServletRequest request;
	@Autowired
	private ItemManager itemManager;
	
	public void execute(Context context, Navigator nav) {
		
		log.error("log-success!");
		
		final ParameterParser rundata = TurbineUtil.getTurbineRunData(request).getParameters(); 
		
		String winnerItemIdStr = rundata.getString("winnerItemId", "0");
		
		String loserItemIdStr = rundata.getString("winnerItemId", "0");
		
		if("0".equals(winnerItemIdStr)){
			return;
		}
		
		long winnerItemId = Long.parseLong(winnerItemIdStr);
		
		long loserItemId = Long.parseLong(loserItemIdStr);
		ItemReqDO itemReq= new ItemReqDO();
		itemReq.setItemId(winnerItemId);
		itemReq.setTagId(0);
		ItemDO winnerItem = itemManager.getItemById(itemReq);

		long betterCount = winnerItem.getBetterCount()+1;
		winnerItem.setBetterCount(betterCount);
		
		try {
			int result = itemManager.updateItem(winnerItem);
			if(result==0){
				
			}
		} catch (Exception e) {

		}
		
		//这里加上商品比较的记录，winnerItemId和loserItemId
		
	}

	public ItemManager getItemManager() {
		return itemManager;
	}

	public void setItemManager(ItemManager itemManager) {
		this.itemManager = itemManager;
	}
}
